import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_app_05/action/states/dark_states.dart';
import 'package:flutter_app_05/action/states/data_manager.dart';
import 'package:flutter_app_05/utils/MyTheme.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:provider/provider.dart';

class Padecalfive extends StatefulWidget {
  @override
  _PadecalfiveoInState createState() => _PadecalfiveoInState();
}

class _PadecalfiveoInState extends State<Padecalfive> {
  String html = "<p/>";
  TextEditingController mianjiController = TextEditingController();
  TextEditingController hotController = TextEditingController();
  TextEditingController oneController = TextEditingController();
  TextEditingController one2Controller = TextEditingController();
  TextEditingController twoController = TextEditingController();
  TextEditingController two2Controller = TextEditingController();
  TextEditingController xisController = TextEditingController();
  bool invalidMianji = false;

  @override
  Widget build(BuildContext context) {
    return Consumer<DartState>(builder: (context, categoryState, child) {
      return columns(categoryState);
    });
  }

  Widget columns(DartState categoryState) {
    Widget h = Container(
      height: 1,
      color: MyTheme(context).getColor("line_color"),
      alignment: Alignment.center,
      margin: EdgeInsets.only(top: 10.0, bottom: 10.0),
    );
    return Container(
      color: MyTheme(context).getColor("bg"),
      child: Column(
        children: [
          Container(
            margin: EdgeInsets.all(10.0),
            padding: EdgeInsets.all(15),
            decoration: new BoxDecoration(
                color: MyTheme(context).getColor("white"),
                borderRadius: new BorderRadius.circular((10.0))),
            alignment: Alignment.center,
            height: 350,
            child: Column(
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: [
                    Expanded(
                        child: Text(
                      "供暖面积",
                      style: TextStyle(
                          color: MyTheme(context).getColor('colorBlack')),
                    )),
                    Container(
                      width: 100.0,
                      child: TextField(
                        textAlign: TextAlign.right,
                        maxLength: 100,
                        decoration: null,
                        controller: mianjiController,
                        inputFormatters: [
                          WhitelistingTextInputFormatter.digitsOnly
                        ],
                        style: TextStyle(color: Colors.green),
                      ),
                    ),
                    Text(
                      "m²",
                      style: TextStyle(
                          color: MyTheme(context).getColor('colorBlack')),
                    ),
                  ],
                ),
                h,
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: [
                    Expanded(
                        child: Text(
                      "热指标",
                      style: TextStyle(
                          color: MyTheme(context).getColor('colorBlack')),
                    )),
                    Container(
                      width: 100.0,
                      child: TextField(
                        textAlign: TextAlign.right,
                        maxLength: 100,
                        decoration: null,
                        controller: hotController,
                        inputFormatters: [
                          WhitelistingTextInputFormatter.digitsOnly
                        ],
                        style: TextStyle(
                            color: MyTheme(context).getColor('colorBlack')),
                      ),
                    ),
                    Text(
                      "W/m²",
                      style: TextStyle(
                          color: MyTheme(context).getColor('colorBlack')),
                    ),
                  ],
                ),
                h,
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: [
                    Expanded(
                        child: Text(
                      "一网供水温度",
                      style: TextStyle(
                          color: MyTheme(context).getColor('colorBlack')),
                    )),
                    Container(
                      width: 100.0,
                      child: TextField(
                        textAlign: TextAlign.right,
                        maxLength: 100,
                        decoration: null,
                        controller: oneController,
                        inputFormatters: [
                          WhitelistingTextInputFormatter.digitsOnly
                        ],
                        style: TextStyle(
                            color: MyTheme(context).getColor('colorBlack')),
                      ),
                    ),
                    Text(
                      "℃",
                      style: TextStyle(
                          color: MyTheme(context).getColor('colorBlack')),
                    ),
                  ],
                ),
                h,
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: [
                    Expanded(
                        child: Text(
                      "一网回水温度",
                      style: TextStyle(
                          color: MyTheme(context).getColor('colorBlack')),
                    )),
                    Container(
                      width: 100.0,
                      child: TextField(
                        textAlign: TextAlign.right,
                        maxLength: 100,
                        decoration: null,
                        controller: one2Controller,
                        inputFormatters: [
                          WhitelistingTextInputFormatter.digitsOnly
                        ],
                        style: TextStyle(
                            color: MyTheme(context).getColor('colorBlack')),
                      ),
                    ),
                    Text(
                      "℃",
                      style: TextStyle(
                          color: MyTheme(context).getColor('colorBlack')),
                    ),
                  ],
                ),
                h,
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: [
                    Expanded(
                        child: Text(
                      "二网供水温度",
                      style: TextStyle(
                          color: MyTheme(context).getColor('colorBlack')),
                    )),
                    Container(
                      width: 100.0,
                      child: TextField(
                        textAlign: TextAlign.right,
                        maxLength: 100,
                        decoration: null,
                        controller: twoController,
                        inputFormatters: [
                          WhitelistingTextInputFormatter.digitsOnly
                        ],
                        style: TextStyle(
                            color: MyTheme(context).getColor('colorBlack')),
                      ),
                    ),
                    Text(
                      "℃",
                      style: TextStyle(
                          color: MyTheme(context).getColor('colorBlack')),
                    ),
                  ],
                ),
                h,
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: [
                    Expanded(
                        child: Text(
                      "二网回水温度",
                      style: TextStyle(
                          color: MyTheme(context).getColor('colorBlack')),
                    )),
                    Container(
                      width: 100.0,
                      child: TextField(
                        textAlign: TextAlign.right,
                        maxLength: 100,
                        decoration: null,
                        controller: two2Controller,
                        inputFormatters: [
                          WhitelistingTextInputFormatter.digitsOnly
                        ],
                        style: TextStyle(
                            color: MyTheme(context).getColor('colorBlack')),
                      ),
                    ),
                    Text(
                      "℃",
                      style: TextStyle(
                          color: MyTheme(context).getColor('colorBlack')),
                    ),
                  ],
                ),
                h,
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: [
                    Expanded(
                        child: Text(
                      "交换系数",
                      style: TextStyle(
                          color: MyTheme(context).getColor('colorBlack')),
                    )),
                    Container(
                      width: 100.0,
                      child: TextField(
                        textAlign: TextAlign.right,
                        maxLength: 100,
                        decoration: null,
                        controller: xisController,
                        inputFormatters: [
                          WhitelistingTextInputFormatter.digitsOnly
                        ],
                        style: TextStyle(
                            color: MyTheme(context).getColor('colorBlack')),
                      ),
                    ),
                    Text(
                      "W/m²",
                      style: TextStyle(
                          color: MyTheme(context).getColor('colorBlack')),
                    ),
                  ],
                ),
                h,
              ],
            ),
          ),
          Center(
            child: Html(data: html),
          ),
          Expanded(
              child: Stack(
            children: [
              Positioned(
                child: Container(
                  height: 60.0,
                  alignment: Alignment.bottomCenter,
                  child: Row(
                    children: [
                      Expanded(
                        child: GestureDetector(
                          child: Container(
                            color: MyTheme(context).getColor("white"),
                            child: Center(
                              child: Text(
                                "重置",
                                style: new TextStyle(
                                    fontSize: 25.0,
                                    color: MyTheme(context)
                                        .getColor('text_color')),
                              ),
                            ),
                          ),
                          onTap: () {
                            mianjiController.text = "";
                            hotController.text = "";
                            oneController.text = "";
                            one2Controller.text = "";
                            twoController.text = "";
                            two2Controller.text = "";
                            xisController.text = "";
                          },
                        ),
                      ),
                      Expanded(
                        child: GestureDetector(
                          child: Container(
                            color: Colors.green,
                            child: Center(
                              child: Text(
                                "提交",
                                style: new TextStyle(
                                    fontSize: 25.0, color: Colors.white),
                              ),
                            ),
                          ),
                          onTap: () {
                            getInfo();
                            setState(() {});
                          },
                        ),
                      )
                    ],
                  ),
                ),
                bottom: 0,
                left: 0,
                right: 0,
              ),
            ],
          )),
        ],
      ),
    );
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  Future getInfo() {
    DataManager.getRsqjs(p: {
      "pwrs": hotController.text,
      "area": mianjiController.text,
      "intemperate": oneController.text,
      "backtemperate": one2Controller.text,
      "newintemperate": twoController.text,
      "newbacktemperate": two2Controller.text,
      "k": xisController.text,
      "coefficient": "1",
      "from": "IOS"
    }).then((value) {
      if (value.data == null) {
        html = value.msg;
      } else {
        html = value.data;
      }
      setState(() {});
    });
  }
}
